package demo8;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @Configuration是Spring容器提供的一个注解
 *
 * @ComponentScan注解
 * 在配置类上使用该注解,用于告知容器扫描哪个包
 */
@Configuration
@ComponentScan("demo8")
public class Config {
    /*
    * 容器初始化的时候这个student实例就能被实例化了
    * */

    @Bean
    public Student initStudent(){
        return new Student();
    }

    @Bean
    public DruidDataSource initDruidDataSource(){
        DruidDataSource ds = new DruidDataSource();
        ds.setUrl("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true");
        ds.setUsername("root");
        ds.setPassword("root");
        ds.setInitialSize(5);
        ds.setMaxActive(30);
        return  ds;
    }
}
